/* 
 * Copyright notice and file header for MQTT client module
 * This file contains the interface definitions for MQTT client functionality
 */

/* 
 * Header guard to prevent multiple inclusions of this header file
 * This ensures the contents are only included once during compilation
 */
#ifndef __MQTT_CLIENT_H__
#define __MQTT_CLIENT_H__

/* 
 * Include standard integer type definitions
 * Provides fixed-width integer types like uint8_t, uint16_t, etc.
 */
#include <stdint.h>

/* 
 * Conditional compilation based on DEBUG flag
 * Defines different MQTT topic names for debug vs production environments
 * Production topics use "sys.upcomm" while debug uses "osmanage"
 */
#ifndef DEBUG
/* 
 * Production topic for publishing APN configuration requests
 * Format: wwan/set/request/sys.upcomm/cfgAPN
 */
#define TOPIC_CONFIG_APN_PUB "wwan/set/request/sys.upcomm/cfgAPN"
/* 
 * Production topic for subscribing to APN configuration responses
 * Format: sys.upcomm/set/response/wwan/cfgAPN
 */
#define TOPIC_CONFIG_APN_SUB "sys.upcomm/set/response/wwan/cfgAPN"
/* 
 * Production topic for publishing cellular module info requests
 * Format: wwan/get/request/sys.upcomm/cellularModuleInfo
 */
#define TOPIC_GET_MODULEINFO_PUB "wwan/get/request/sys.upcomm/cellularModuleInfo"
/* 
 * Production topic for subscribing to cellular module info responses
 * Format: sys.upcomm/get/response/wwan/cellularModuleInfo
 */
#define TOPIC_GET_MODULEINFO_SUB "sys.upcomm/get/response/wwan/cellularModuleInfo"
/* 
 * Production topic for publishing cellular network info requests
 * Format: wwan/get/request/sys.upcomm/cellularNetworkInfo
 */
#define TOPIC_GET_NETWORKINFO_PUB "wwan/get/request/sys.upcomm/cellularNetworkInfo"
/* 
 * Production topic for subscribing to cellular network info responses
 * Format: sys.upcomm/get/response/wwan/cellularNetworkInfo
 */
#define TOPIC_GET_NETWORKINFO_SUB "sys.upcomm/get/response/wwan/cellularNetworkInfo"
#else
/* 
 * Debug topic for publishing APN configuration requests
 * Uses "osmanage" instead of "sys.upcomm" for testing purposes
 */
#define TOPIC_CONFIG_APN_PUB "wwan/set/request/osmanage/cfgAPN"
/* 
 * Debug topic for subscribing to APN configuration responses
 * Uses "osmanage" instead of "sys.upcomm" for testing purposes
 */
#define TOPIC_CONFIG_APN_SUB "osmanage/set/response/wwan/cfgAPN"
/* 
 * Debug topic for publishing cellular module info requests
 * Uses "osmanage" instead of "sys.upcomm" for testing purposes
 */
#define TOPIC_GET_MODULEINFO_PUB "wwan/get/request/osmanage/cellularModuleInfo"
/* 
 * Debug topic for subscribing to cellular module info responses
 * Uses "osmanage" instead of "sys.upcomm" for testing purposes
 */
#define TOPIC_GET_MODULEINFO_SUB "osmanage/get/response/wwan/cellularModuleInfo"
/* 
 * Debug topic for publishing cellular network info requests
 * Uses "osmanage" instead of "sys.upcomm" for testing purposes
 */
#define TOPIC_GET_NETWORKINFO_PUB "wwan/get/request/osmanage/cellularNetworkInfo"
/* 
 * Debug topic for subscribing to cellular network info responses
 * Uses "osmanage" instead of "sys.upcomm" for testing purposes
 */
#define TOPIC_GET_NETWORKINFO_SUB "osmanage/get/response/wwan/cellularNetworkInfo"
#endif

/* 
 * Structure definition for cellular module information
 * Contains technical details about the cellular hardware module
 */
typedef struct
{
    /* 
     * SIM slot identifier string
     * Identifies which SIM slot this module information belongs to
     */
    char simSlot[32];
    /* 
     * Cellular module name/model
     * Contains the manufacturer and model name of the cellular module
     */
    char moduleName[32];
    /* 
     * Firmware version string
     * Contains the current firmware version running on the cellular module
     */
    char firmwareVersion[64];
    /* 
     * International Mobile Equipment Identity
     * Unique identifier for the cellular hardware device (15-17 digits)
     */
    char imei[64];
} CellularModuleInfo;

/* 
 * Structure definition for cellular network information
 * Contains current network connection status and parameters
 */
typedef struct
{
    /* 
     * Mobile Network Operator name
     * Identifies the cellular service provider (e.g., Verizon, AT&T)
     */
    char mno[64];
    /* 
     * International Mobile Subscriber Identity
     * Unique identifier for the SIM card and subscriber
     */
    char imsi[64];
    /* 
     * Integrated Circuit Card Identifier
     * Unique serial number of the SIM card
     */
    char iccid[64];
    /* 
     * SIM slot identifier string
     * Identifies which SIM slot this network information belongs to
     */
    char simSlot[32];
    /* 
     * SIM card status information
     * Indicates whether SIM is ready, locked, or has errors
     */
    char simStatus[32];
    /* 
     * Network connection mode
     * Specifies the current network technology (e.g., LTE, 3G, 2G)
     */
    char mode[32];
    /* 
     * Received Signal Strength Indicator
     * Measures the power level of received cellular signal in dBm
     */
    char rssi[32];
    /* 
     * Reference Signal Received Power
     * LTE-specific signal quality measurement in dBm
     */
    char rsrp[32];
    /* 
     * Reference Signal Received Quality
     * LTE-specific signal quality measurement in dB
     */
    char rsrq[32];
    /* 
     * Signal to Interference plus Noise Ratio
     * Measures signal quality relative to noise and interference
     */
    char sinr[32];
    /* 
     * IP address assigned to the device
     * The Internet Protocol address obtained from the network
     */
    char ipAddress[32];
    /* 
     * Network subnet mask
     * Defines the network portion of the IP address
     */
    char netMask[32];
    /* 
     * Network gateway address
     * The router IP address for network communication
     */
    char gateway[32];
    /* 
     * Dial-up connection type
     * Specifies the method used to establish network connection
     */
    char dialType[32];
    /* 
     * Dial-up connection status
     * Indicates whether network connection is established or not
     */
    char dialStatus[32];
} CellularNetworkInfo;

/* 
 * Structure definition for APN configuration information
 * Contains Access Point Name settings for cellular data connection
 */
typedef struct
{
    /* 
     * SIM slot identifier string
     * Identifies which SIM slot this APN configuration applies to
     */
    char simSlot[32];
    /* 
     * Access Point Name
     * The gateway between mobile network and external networks
     */
    char apnName[32];
    /* 
     * APN username for authentication
     * Optional username required by some mobile operators
     */
    char apnUser[32];
    /* 
     * APN password for authentication
     * Optional password required by some mobile operators
     */
    char apnPsw[32];
} configAPNInfo;

/* 
 * Function prototype for generic MQTT message exchange
 * Sends a request and waits for response using specified topics
 * Returns success/failure status code
 */
uint8_t get_message(const char *publish_topic, const char *sub_topic, const char *body, char *result);

/* 
 * Function prototype to retrieve cellular module information
 * Queries and returns hardware details of the cellular module
 * Returns success/failure status code
 */
uint8_t get_cellularModuleInfo(CellularModuleInfo *moduleInfo);

/* 
 * Function prototype to retrieve cellular network information
 * Queries and returns current network connection status and parameters
 * Returns success/failure status code
 */
uint8_t get_cellularNetworkInfo(CellularNetworkInfo *networkInfo);

/* 
 * Function prototype to configure APN settings
 * Applies new APN configuration and returns operation status
 * Returns success/failure status code
 */
uint8_t get_configAPN(configAPNInfo *confiInfo, char *status);

/* 
 * End of header guard conditional compilation block
 * Matches the #ifndef __MQTT_CLIENT_H__ at the beginning
 */
#endif /* __MQTT_CLIENT_H__ */